package com.ysd.crm.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.Getter;
import lombok.Setter;

@Entity
@Table
@Getter
@Setter 
public class Roles {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer rid;//角色编号
	private String rname;//角色名称
	private String details;//角色介绍
	
	@JsonIgnore
	@ManyToMany
	@Cascade(CascadeType.SAVE_UPDATE)
	@JoinTable(name="user_role_tb",joinColumns = @JoinColumn(name="role_id"),inverseJoinColumns = @JoinColumn(name="user_id"))
	@NotFound(action = NotFoundAction.IGNORE)//找不到外键引用时忽略
	private Set<Users> userSet = new HashSet<Users>();
	
	@ManyToMany
	@Cascade(CascadeType.SAVE_UPDATE)
	@JoinTable(name="role_module_tb",joinColumns = @JoinColumn(name="role_id"),inverseJoinColumns = @JoinColumn(name="module_id"))
	@NotFound(action = NotFoundAction.IGNORE)//找不到外键引用时忽略
	private Set<Modules> moduleSet = new HashSet<Modules>();
}
